//让severFifo 来读取
#include "comm.h"

using namespace std;

int main()
{
    umask(0);
    if(mkfifo(IPC_PATH,0600) != 0)
    {
        cerr<<"mkfifo client" <<endl;
        return 1;
    }

    int pipeFd = open(IPC_PATH,O_RDONLY);
    if(pipeFd < 0)
    {
        cerr << "open fifo error" << endl;
        return 2;
    }
    //正常通信
    char buffer[1024];
    while(true)
    {
        ssize_t s = read(pipeFd,buffer,sizeof(buffer) - 1);
        if(s > 0 )
        {
            buffer[s] = '\0';
            cout<<" 客户端-->服务器#  " << buffer << endl;
        }
        else if(s == 0)
        {
            cout<< "客户端退出了,我也退出了";
            break;
        }
        else
        {
            //do nothing
            cout << "read error" <<  strerror(errno) <<endl;
            break;
        }
    }

    close(pipeFd);
    cout<< "服务端退出啦"<<endl;
    unlink(IPC_PATH);
    return 0;
}